<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>async 和 promise 的 使用</h1>

    <script>
      async function fartherFun() {
        await fun('历史')
        console.log('检查 什么时候执行')
      }
      async function fun(name) {
        console.log('hello world' + name)
        // return await ds()
        await ds()
        console.log(name + '你好')
      }
      async function ds() {
        console.log('我是定时器里的 同步方法')
        return new Promise((resolve, reject) => {
          let intwo = setInterval(() => {
            console.log('定时器完成')
            clearInterval(intwo)
            resolve()
          }, 4000)
        })
      }
      // fun('历史')
      fartherFun()
      // console.log(a)
    </script>
  </body>
</html>
